/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 * @description 
 */

var getIntersectionNode = function (headA, headB) {
    if (!headA || !headB) {
        return null
    }
    let h1 = headA
    let h2 = headB
    while (h1 !== h2) {
        if (h1 === null) {
            h1 = headB
        } else {
            h1 = h1.next
        }
        if (h2 === null) {
            h2 = headA
        } else {
            h2 = h2.next
        }
    }
    return h1
};